home *** CD-ROM | disk | FTP | other *** search
- ; Factorial the recursive way
-
- (const NUMBER 0x03)
- (defun
- fact ;; the recursive part. input: x output: x!
- {
- (if (== (arg 0) 0) 1 ; 0! = 1
- (* (arg 0) (fact (- (arg 0) 1))) ; x! = x * (x-1)!
- )
- }
- ! ;; the main routine
- {
- (int x)
- (x (convert-to NUMBER (ask "Take factorial of: ")))
- (msg x "! = " (fact x))
- }
- MAIN { (!) } ;; (! 5) produces "5! = 120"
- )
-